<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="主推公众号" prop="sys_user_id">
        <el-select v-model="queryParams.sys_user_id" placeholder="请选择主推公众号" filterable clearable style="width:150px">
          <el-option v-for="customer in customerList" :key="customer.id"
            :label="customer.username + '(' + customer.nickname + ')'" :value="customer.id" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="产品" prop="spec_id">
        <el-select
          v-model="queryParams.spec_id"
          placeholder="请选择产品"
          filterable
          clearable
        >
          <el-option
            v-for="product in productList"
            :key="product.id"
            :label="product.cate?.name + product.face_value"
            :value="product.id"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="分类" prop="cate_id">
        <el-select v-model="queryParams.cate_id" placeholder="请选择分类" filterable clearable style="width:150px">
          <el-option v-for="cate in cateList" :key="cate.id" :label="cate.name" :value="cate.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="面值" prop="face_value">
        <el-input placeholder="面值" v-model="queryParams.face_value" clearable></el-input>
      </el-form-item>

      <el-form-item label="支付渠道" prop="payment_id">
        <el-select v-model="queryParams.payment_id" placeholder="请选择支付渠道" filterable clearable style="width:150px">
          <el-option v-for="item in payChannel" :key="item.id" :label="item.payment_name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="业务类型" prop="recharge_type">
        <el-select v-model="queryParams.recharge_type" placeholder="业务类型" clearable style="width: 100px">
          <el-option label="话费" value="1" />
          <el-option label="流量" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="运营商" prop="isp">
        <el-select v-model="queryParams.isp" placeholder="运营商" clearable style="width: 100px">
          <el-option label="移动" value="1" />
          <el-option label="联通" value="2" />
          <el-option label="电信" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="处理方式" prop="is_auto">
        <el-select v-model="queryParams.is_auto" placeholder="处理方式" clearable style="width: 100px">
          <el-option v-for="dict in czType" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="状态" prop="order_status">
        <el-select v-model="queryParams.order_status" placeholder="状态" clearable style="width: 150px">
          <el-option label="下单成功" value="1" />
          <el-option label="充值中" value="2" />
          <el-option label="充值完成" value="3" />
          <el-option label="充值失败" value="4" />
          <el-option label="压单" value="5" />
          <el-option label="失败拦截" value="6" />
          <el-option label="待回调" value="7" />
        </el-select>
      </el-form-item>
      <el-form-item label="微信退款" prop="refund_status">
        <el-select v-model="queryParams.refund_status" placeholder="微信退款状态" clearable style="width: 150px">
          <el-option label="未退款" value="0" />
          <el-option label="退款中" value="1" />
          <el-option label="退款成功" value="2" />
          <el-option label="退款失败" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="平台状态" prop="plat_status">
        <el-select v-model="queryParams.plat_status" placeholder="平台状态" clearable style="width: 150px">
          <el-option label="未扣款" value="1" />
          <el-option label="已扣款" value="2" />
          <el-option label="已退款" value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="省份" prop="province_id">
        <el-select v-model="queryParams.province_id" placeholder="省份" clearable filterable
          @change="handleProvinceChange" @clear="handleProvinceClear" style="width: 120px">
          <el-option v-for="province in provinceList" :key="province.id" :label="province.short_name"
            :value="province.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="城市" prop="city_id">
        <el-select v-model="queryParams.city_id" placeholder="城市" clearable filterable style="width: 120px">
          <el-option v-for="city in cityList" :key="city.id" :label="city.short_name" :value="city.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="渠道" prop="channel_id">
        <el-select v-model="queryParams.channel_id" placeholder="请选择渠道" filterable clearable style="width:150px">
          <el-option v-for="channel in channelList" :key="channel.id" :label="channel.channel_name"
            :value="channel.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="平台订单号" prop="order_sn">
        <el-input v-model="queryParams.order_sn" placeholder="请输入平台订单号" clearable style="width: 260px" />
      </el-form-item>
      <el-form-item label="粉丝ID" prop="mp_user_id">
        <el-input v-model="queryParams.mp_user_id" placeholder="请输入粉丝ID" clearable style="width: 160px" />
      </el-form-item>
      <el-form-item label="昵称" prop="nickname">
        <el-input v-model="queryParams.nickname" placeholder="请输入昵称" clearable style="width: 160px" />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input v-model="queryParams.mobile" placeholder="请输入手机号" clearable style="width: 160px" />
      </el-form-item>
      <!-- <el-form-item label="平台订单" prop="is_member_order">
        <el-select
          v-model="queryParams.is_member_order"
          placeholder="平台订单"
          clearable
          style="width: 150px"
        >
          <el-option label="是" value="0" />
          <el-option label="否" value="1" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="创建时间">
        <el-date-picker ref="datePicker" v-model="dateRange" style="width: 380px" type="datetimerange" value-format="x"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="defaultTime"></el-date-picker>
        <!-- value-format="yyyy/MM/dd HH:mm:ss" -->
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <h3>订单操作只能针对平台自己的渠道,商户自建渠道订单无法修改</h3>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- v-hasPermi="['api:v1:updateCzChannel']" -->
        <el-button type="primary" plain icon="Download" size="small" @click="handleExport"
          v-hasPermi="['api:order:exportUserOrderList']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Edit" size="small" :disabled="multiple"
          v-hasPermi="['api:order:stopCzOrder']" @click="handleStop">终止订单</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="CircleCloseFilled" size="small" :disabled="multiple"
          @click="handleRefundOrder" v-hasPermi="['api:order:refundOrder']">申请退单</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="Edit" size="small" :disabled="multiple" @click="handleReSubmit"
          v-hasPermi="['api:order:orderReSubmit']">重提订单</el-button>
      </el-col>

      <!--
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          v-hasPermi="['api:v1:cacheOrderSubmit']"
          @click="handleCacheSubmit"
          >压单重提</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          v-hasPermi="['api:v1:stopFailOrderSubmit']"
          @click="handleStopFailSubmit"
          >拦截重提</el-button
        >
      </el-col>
      -->
      <el-col :span="1.5">
        <el-button type="primary" plain icon="Edit" size="small" :disabled="multiple" @click="handleMutiStatus"
          v-hasPermi="['api:order:changeStatus']">批量改状态</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Position" size="small" :disabled="multiple" @click="handleRefund"
          v-hasPermi="['api:order:refund']">微信退款</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Edit" size="small" :disabled="multiple" @click="handleProcessType(0)"
          v-hasPermi="['api:order:updateOrderProcessType']">手动处理</el-button>
        <!-- v-hasPermi="['api:v1:updateOrderProcessType']" -->
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" size="small" :disabled="multiple" @click="handleProcessType(1)"
          v-hasPermi="['api:order:updateOrderProcessType']">自动处理</el-button>
        <!-- v-hasPermi="['api:v1:updateOrderProcessType']" -->
      </el-col>

      <!-- // v-hasPermi="['api:v1:updateCzOrderStatus']" -->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="expand">
        <template #default="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="优惠券" label-width="120px">
                <div >{{props.row?.userCoupon?.title}}
                  <span style="color: red;">(优惠金额：{{ props.row?.used_amount }})</span>
                </div>
            </el-form-item>
            <el-form-item label="用户是否支付" label-width="120px">
              <span v-if="props.row.pay_status == 1">已支付</span>
              <span v-if="props.row.pay_status == 0">未支付</span>
            </el-form-item>
            <el-form-item label="平台订单状态" label-width="120px">
              <span v-if="props.row.plat_status == 1">未扣款</span>
              <span v-if="props.row.plat_status == 2">已扣款</span>
              <span v-if="props.row.plat_status == 3">已退款</span>
            </el-form-item>
            <!-- <el-form-item label="超时时间">
              <span>{{ parseTime(props.row.timeout) }}</span>
            </el-form-item> -->
            <!-- <el-form-item label="商户拿货价">
              <span>{{ props.row.user_price }}</span>
            </el-form-item>
            <el-form-item label="成本">
              <span>{{ props.row.const_price }}</span>
            </el-form-item> -->
            <el-form-item label="凭证">
              <span>{{ props.row.voucher }}</span>
            </el-form-item>
            <el-form-item label="返佣:">
              <template v-if="props.row.commission">
                <span>{{ props.row.commission.name }}</span>
                <div style="margin:0 15px;">返佣类型：
                  <span v-if="props.row.commission.mode == 1">销售额百分比</span>
                  <span v-if="props.row.commission.mode == 2">指定金额</span>
                  <span v-if="props.row.commission.mode == 3">纯利润百分比</span>
                </div>
                一级：<span style="color:red;margin-right: 15px;;">{{ props.row.commission_money1 }}</span>
                二级：<span style="color:red;">{{ props.row.commission_money2 }}</span>
              </template>
              <template v-else>
                <span>未设置返佣</span>
              </template>
            </el-form-item>
            <el-form-item label="备注">
              <span>{{ props.row.remark }}</span>
            </el-form-item>
            <el-form-item label="操作描述">
              <span>{{ props.row.act_remark }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="主推公众号" align="center" prop="user.username" />
      <el-table-column label="来源公众号" align="center" prop="fromUser.username" />
      <el-table-column label="粉丝" align="center" prop="mpUser.nickname" />
      <el-table-column label="粉丝ID" align="center" prop="mpUser.id" />
      <!-- width="240" -->
      <el-table-column label="订单号" align="center" :show-overflow-tooltip="false" prop="order_sn" />
      <el-table-column label="手机号" align="center" width="110" prop="mobile" />

      <el-table-column label="产品" align="center" prop="product_name">
        <template #default="scope">
          <span>{{ scope.row.goods_full_title }}</span>
        </template>
      </el-table-column>
      <el-table-column label="业务" align="center" prop="recharge_type">
        <template #default="scope">
          <el-tag v-if="scope.row.recharge_type == 1">话费</el-tag>
          <el-tag v-if="scope.row.recharge_type == 2">流量</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="归属地/运营商" align="center" prop="isp">
        <template #default="scope">
          <span>{{ scope.row.area_name }}</span>
          <div v-if="scope.row.isp == 1">移动</div>
          <div v-if="scope.row.isp == 2">联通</div>
          <div v-if="scope.row.isp == 3">电信</div>
          <!-- <dict-tag :options="dict.type.cz_isp" :value="scope.row.isp" /> -->
        </template>
      </el-table-column>
      <el-table-column label="售价/成本" align="center" prop="sale_price" width="180" :show-overflow-tooltip="false">
        <template #default="scope">
          <el-tag type="info">{{ scope.row.sale_price }}</el-tag>/
          <!-- <el-tag type="warning">{{ scope.row.user_price }}</el-tag> -->
          <!-- / -->
          <el-tag type="success">{{ scope.row.const_price }}</el-tag>

          <!-- <dict-tag :options="dict.type.cz_isp" :value="scope.row.isp" /> -->
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="order_status">
        <template #default="scope">
          <el-tag v-if="scope.row.order_status == 1">下单成功</el-tag>
          <el-tag type="info" v-if="scope.row.order_status == 2">充值中</el-tag>
          <el-tag type="success" v-if="scope.row.order_status == 3">充值成功</el-tag>
          <el-tag type="success" v-if="scope.row.order_status == 7">待回调</el-tag>
          <el-tag type="danger" v-if="scope.row.order_status == 4">充值失败</el-tag>
          <el-tag type="warning" v-if="scope.row.order_status == 5">压单</el-tag>
          <el-tag type="warning" v-if="scope.row.order_status == 6">失败拦截</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="微信退款" align="center" prop="refund_status">
        <template #default="{ row }">
          <el-tag v-if="row.refund_status == 2" type="success">退款成功</el-tag>
          <el-tag v-if="row.refund_status == 3" type="danger">退款失败</el-tag>
          <el-tag v-if="row.refund_status == 1" type="info">退款中</el-tag>
          <el-tag v-if="row.refund_status == 0">未退款</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="收款方式" align="center" prop="payment_name" :show-overflow-tooltip="false">
        <template #default="{ row }">
          <!-- <el-button size="small" type="success">{{ row.pay?.payment_name || "无" }}</el-button> -->
          <span>{{ row.pay?.payment_name || "无" }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="平台状态" align="center" prop="refund_status">
        <template #default="{ row }">
          <el-tag v-if="row.plat_status == 2" type="success">已扣款</el-tag>
          <el-tag v-if="row.plat_status == 1">未扣款</el-tag>
          <el-tag v-if="row.plat_status == 3" type="success">已退款</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column label="分佣结算" align="center" prop="commission_status">
        <template #default="{ row }">
          <el-tag v-if="row.commission_status == 1" type="success">已完成</el-tag>
          <el-tag v-else>未完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="处理方式" align="center" prop="is_auto">
        <template #default="scope">
          <el-tag v-if="scope.row.is_auto == 1" type="success">自动</el-tag>
          <el-tag v-if="scope.row.is_auto == 0" type="warning">手动</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="渠道" align="center" prop="channel.channel_name" />
      <!-- <el-table-column label="平台订单" align="center" prop="is_member_order">
        <template #default="scope">
          <el-tag v-if="scope.row.is_member_order == 1" type="warning"
            >否</el-tag
          >
          <el-tag v-else type="success">是</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column label="是否终止" align="center" prop="is_stop">
        <template #default="scope">
          <el-tag v-if="scope.row.is_stop == 1" type="success">是</el-tag>
          <el-tag v-else>否</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建/更新时间" align="center" prop="created_at" width="180">
        <template #default="scope">
          <span>{{ scope.row.created_at }}</span>
          <br />
          <span>{{ scope.row.updated_at }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />

    <el-dialog title="批量改状态" v-model="open" width="600px" append-to-body :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="已选择数量">
          {{ ids.length }}
        </el-form-item>
        <el-form-item label="温馨提示">
          <span style="color: red">请确保没有勾选错订单以及要更改的订单状态!！！</span>
        </el-form-item>
        <el-form-item label="修改状态" prop="order_status">
          <el-radio-group v-model="form.order_status">
            <el-radio-button :label="2">充值中</el-radio-button>
            <el-radio-button :label="3">充值完成</el-radio-button>
            <el-radio-button :label="4">充值失败</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="密码" v-if="form.order_status == 4" prop="password">
          <el-input v-model="form.password" placeholder="请输入登录密码确认操作" type="password" show-password />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入备注"></el-input>
        </el-form-item>
        <!-- <el-form-item
          label="是否回调"
          v-if="form.order_status == 3 || form.order_status == 4"
          prop="is_callback"
        >
          <el-radio-group v-model="form.is_callback" size="medium">
            <el-radio-button :label="0">不回调</el-radio-button>
            <el-radio-button :label="1">回调给客户</el-radio-button>
          </el-radio-group>
        </el-form-item> -->
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="loading2" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog :title="title2" v-model="open2" width="600px" append-to-body :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-form ref="form2" :model="form2" :rules="rules2" label-width="100px">
        <el-form-item label="已选择数量">
          {{ ids.length }}
        </el-form-item>

        <el-form-item label="变更渠道" prop="change_channel">
          <el-radio-group v-model="form2.change_channel">
            <el-radio-button :label="0">不变更</el-radio-button>
            <el-radio-button :label="1">变更渠道</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="密码" v-if="form2.change_channel == 1" prop="password">
          <el-input v-model="form2.password" placeholder="请输入登录密码确认操作" type="password" show-password />
        </el-form-item>
        <el-form-item label="温馨提示" v-if="form2.change_channel == 1">
          <span style="color: red">请确认不要选错渠道，否则损失自负。请确认已提前添加好渠道产品，否则重提会失败。</span>
        </el-form-item>
        <el-form-item label="渠道" prop="channel_id" v-if="form2.change_channel == 1">
          <el-select v-model="form2.channel_id" placeholder="请选择渠道" filterable clearable>
            <el-option v-for="channel in channelList" :key="channel.id" :label="channel.channel_name"
              :value="channel.id" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="loading2" type="primary" @click="submitForm2">确 定</el-button>
          <el-button @click="cancel2">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <el-dialog title="退款" v-model="openRefund" width="600px" append-to-body :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-form ref="formRefund" :model="formRefund" :rules="formRefundRules" label-width="100px">
        <el-form-item label="退款数">
          {{ ids.length }}
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input v-model="formRefund.password" placeholder="请输入登录密码确认操作" type="password" show-password />
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="formRefund.remark" type="textarea" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item label="温馨提示">
          <span style="color: red">请确保订单没有勾选错误，此操作将会退款金额给粉丝！</span>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="loading3" type="primary" @click="submitForm3">确 定</el-button>
          <el-button @click="openRefund = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import {
  getList as getUserCzOrderList,
  changeStatus as updateCzOrderStatus,
  orderReSubmit,
  updateOrderProcessType,
  refund,
  stopCzOrder,
  refundOrder
} from "@/api/platform/czOrder";

import { getListAll as listAllCzProduct } from "@/api/platform/czProductSpec";
import { getAllList as getCateListAll } from "@/api/platform/czProductCate";
import { getArea2 as getAreas } from "@/api/common";
import { getAllList as listAllCustomer } from "@/api/platform/merchant";
import { getAllList as listAllChannel } from "@/api/channel";
import { getPayAllList } from "@/api/platform/paySet";

export default {
  name: "platformczOrderindex",
  //   dicts: ["cz_product_type", "cz_order_status", "cz_isp"],
  data() {
    return {
      payChannel: [],
      cateList: [],
      openRefund: false,
      formRefund: {
        remark: undefined,
        password: undefined,
      },
      // 遮罩层
      loading: true,
      loading2: false,

      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      dataList: [],
      customerList: [],
      productList: [],
      czType: [
        {
          label: "人工处理",
          value: 0,
        },
        {
          label: "自动处理",
          value: 1,
        },
      ],
      // 省份列表
      provinceList: [],
      channelList: [],

      // 省份列表
      cityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: this.getTimeFilterDefault(true),
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sys_user_id: undefined,
        spec_id: undefined,
        recharge_type: undefined,
        isp: undefined,
        order_status: undefined,
        province_id: undefined,
        city_id: undefined,
        face_value: undefined,
        order_sn: undefined,
        user_order_sn: undefined,
        mobile: undefined,
        channel_id: undefined,
        batch_order_sn: undefined,
        is_auto: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        order_status: [
          { required: true, message: "请选择状态", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      title2: "",
      open2: false,
      form2: {},
      rules2: {
        change_channel: [
          { required: true, message: "请选择是否变更渠道", trigger: "blur" },
        ],
        channel_id: [
          {
            required: true,
            message: "请选择渠道",
            trigger: "blur",
          },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      formRefundRules: {
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
      act: 0,
      loading3: false,
      open3: false,
      form3: {},
    };
  },
  created() {
    this.getCustomerList();
    this.getProvinceList();
    // this.getAllProductList();
    this.getChannelList();
    this.getCateListAll();
    this.getList();
    this.getPayAllList();

  },
  computed: {
    defaultTime() {
      return [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)];
    },
  },
  methods: {
    async getPayAllList() {
      const { data } = await getPayAllList();
      this.payChannel = data;
    },
    async getCateListAll() {
      const { data } = await getCateListAll();
      console.log(data);
      this.cateList = data;
    },
    /** 查询字典类型列表 */
    getList() {
      this.loading = true;
      const params = this.addDateRange(this.queryParams, this.dateRange);
      params.created_at = [params.params.beginTime, params.params.endTime];
      delete params.params;
      console.log(params);
      getUserCzOrderList(params).then((response) => {
        const data = response.data;
        this.dataList = data.items;
        this.total = data.total;
        this.loading = false;
      });
    },
    getChannelList() {
      listAllChannel().then((response) => {
        this.channelList = response.data;
      });
    },
    getAllProductList() {
      listAllCzProduct().then((response) => {
        this.productList = response.data;
      });
    },
    getCustomerList() {
      listAllCustomer().then((response) => {
        this.customerList = response.data;
      });
    },
    getProvinceList() {
      // this.loading = true;
      getAreas({ level_type: 1 }).then((response) => {
        this.provinceList = response.data;
        // this.loading = false;
      });
    },
    getCityList(id) {
      getAreas({ level_type: 2, parent_id: id }).then((response) => {
        this.cityList = response.data;
      });
    },
    handleProvinceChange(val) {
      if (val) {
        // 清除输入
        this.queryParams.city_id = null;
        this.getCityList(val);
      }
    },
    submitForm3() {
      this.$refs.formRefund.validate(async (valid) => {
        if (valid) {
          this.loading3 = true;
          console.log(this.formRefund, this.ids);
          const params = {
            ids: this.ids,
            order_remark: this.formRefund.remark,
            password: this.formRefund.password,
          };
          try {
            await refund(params);
            this.getList();
            this.$modal.msgSuccess("操作成功");
            this.openRefund = false;
            this.open3 = false;
          } finally {
            this.loading3 = false;
          }
        }
      });
    },
    handleRefund() {
      this.formRefund = {
        remark: undefined,
        password: undefined,
      };
      this.resetForm("formRefund");
      this.openRefund = true;
    },
    handleProvinceClear() {
      this.queryParams.city_id = undefined;
      this.cityList = [];
    },
    submitForm: function () {
      this.loading2 = true;
      this.$refs["form"].validate((valid) => {
        if (valid) {
          updateCzOrderStatus({ ...this.form, ids: this.ids })
            .then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            })
            .finally(() => {
              this.loading2 = false;
            });
        } else {
          this.loading2 = false;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        order_status: undefined,
        is_callback: undefined,
        remark: undefined,
        password: undefined,
      };
      this.resetForm("form");
    },
    handleMutiStatus() {
      this.reset();
      this.open = true;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = this.getTimeFilterDefault(true);
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /**订单回调*/
    handleCallback() {
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm("确认要回调所选的订单吗？")
        .then(function () {
          return czOrderCallback(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 终止订单操作 */
    handleStop(row) {
      const order_ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认要终止ID为[" + order_ids + "]的订单数据项？")
        .then(function () {
          return stopCzOrder(order_ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("终止成功，请耐心等待渠道回调。");
        })
        .catch(() => { });
    },
    //拦截重提
    handleStopFailSubmit() {
      this.reset2();
      this.title2 = "拦截重提";
      this.open2 = true;
      this.act = 2;
      return;
      /*
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm("确认要重新提交失败拦截的订单吗？")
        .then(function () {
          return stopFailOrderSubmit(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .finally(() => {
          this.loading = false;
        });
      */
    },
    /** 导出按钮操作 */
    handleExport() {
      // 导出勾选的订单
      const orderIds = this.ids || [];
      console.log(orderIds);
      if (orderIds.length) {
        this.download(
          "api/order/exportUserOrderList",
          { ids: orderIds },
          "客户订单导出[" + this.parseTime(new Date().getTime()) + "].csv"
        );
      } else {
        const obj = this.addDateRange(this.queryParams, this.dateRange);
        obj.created_at = [obj.params.beginTime, obj.params.endTime];
        delete obj.params;
        this.download(
          "api/order/exportUserOrderList",
          obj,
          "客户订单导出[" + this.parseTime(new Date().getTime()) + "].csv"
        );
      }
    },
    //压单重提
    handleCacheSubmit() {
      this.reset2();
      this.title2 = "压单重提";
      this.open2 = true;
      this.act = 1;
      return;
      /*
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm("确认要重新提交压单缓存订单吗？")
        .then(function () {
          return cacheOrderSubmit(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .finally(() => {
          this.loading = false;
        });
        */
    },
    handleReSubmit() {
      this.reset2();
      this.title2 = "重提订单";
      this.open2 = true;
      return;
    },
    // 处理方式改变
    handleProcessType(type) {
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm(
          "确认要改变处理方式为：[" +
          (type == 1 ? "自动" : "手动") +
          "处理] 吗？"
        )
        .then(function () {
          return updateOrderProcessType({ ids, type });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("操作成功");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    handleRefundOrder() {
      this.loading = true;
      const ids = this.ids;
      this.$modal
        .confirm("只有充值中订单且渠道支持API退单的才可申请退单，确定要退单吗？")
        .then(function () {
          return refundOrder(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("已申请退单，请等待渠道返回退单结果！");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
    },
    handleSelectionChange2(selection) {
      this.multipleSelection2 = selection;
      this.ids2 = selection.map((item) => item.id);
      this.single2 = selection.length != 1;
      // this.multiple2 = !selection.length;
    },
    cancel2() {
      this.open2 = false;
      this.reset2();
    },
    reset2() {
      this.act = 0;
      this.form2 = {
        change_channel: undefined,
        password: undefined,
        channel_id: undefined,
      };
      this.resetForm("form2");
    },
    //压单重提
    submitForm2() {
      this.loading2 = true;
      const ids = this.ids;
      this.$refs["form2"].validate((valid) => {
        if (valid) {
          orderReSubmit({ ...this.form2, ids })
            .then((res) => {
              this.getList();
              this.$modal.msgSuccess("操作成功");
              this.open2 = false;
            })
            .finally(() => {
              this.loading2 = false;
            });
        } else {
          this.loading2 = false;
        }
      });
    },
  },
};
</script>
<style>
.demo-table-expand {
  padding: 0 10px;
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 33.3%;
}
</style>
